
import { _decorator, Component, Node } from 'cc';
import { AudioManager } from '../../../common/src/manager/AudioManager';
import { UIManager } from '../../../framework/ui/uimanager/UIManager';
import { GGStore } from '../../../framework/core/base/GGStore';
import { WECHAT } from 'cc/env';
import { MonoUIPanel } from '../../../common/src/mono/MonoUIPanel';
import DataMgr from '../../../common/src/util/DataMgr';
import { EVENT_NAMES } from '../../../common/src/util/Enums';
import Config from '../../../common/src/util/Config';
const { ccclass, property } = _decorator;

@ccclass('MoneyDialog')
export class MoneyDialog extends MonoUIPanel {    
    // =======================================
    // Component 事件
    // =======================================
    /** 关闭面板. */
    private async onClosePanel() {
        AudioManager.playButton()
        await this.onExitAnimation()
        UIManager.close("money:res/prefab/MoneyDialog")
    }

    public OnClickLookButton(){
        AudioManager.playButton();
        if(WECHAT){
            window.gameSdk.sdk.showRewardVideoAd({
                positionTag:"视频标记点位",
                callback: (err, res) => {
                    if (!err) {
                        DataMgr.money = DataMgr.money + Config.videoAddMoney
                        gg.systemEvent.emit(EVENT_NAMES.UPDATE_START_INFO);
                        this.onClosePanel()
                    }else{
                        // 根据游戏内容需求是否需要使用
                        if(res.code == 1001){ 
                            console.log("视频获取显示失败");
                        }else{
                            console.log("未完整观看视频");
                        }
                    }

                    AudioManager.stopCurrent()
                    AudioManager.playBackGroundMusic()
                }
            });
        } else{
            DataMgr.money = DataMgr.money + Config.videoAddMoney
            gg.systemEvent.emit(EVENT_NAMES.UPDATE_START_INFO);
            this.onClosePanel()
        }
    }
}


